package com.yunhe.java.pro14;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeMap;
import java.util.function.BiConsumer;

/**
 * Created by Administrator on 2017/8/10 0010.
 */
public class JiHeTreeMap {
    public static void main(String[] args) {
        //创建对象
        Student stu1 = new Student("Jack", 1);
        Student stu2 = new Student("Eva", 7);
        Student stu3 = new Student("Sam", 5);
        Student stu4 = new Student("John", 2);

        TreeMap<Integer,String> map=new TreeMap<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                int i=0;
                if(o1>o2){
                    i=-1;
                }
                if(o1<o2){
                    i=1;
                }
                return i;
            }
        });//treemap集合

        //添加对象
        map.put(stu1.getId(),stu1.getName());
        map.put(stu2.getId(),stu2.getName());
        map.put(stu3.getId(),stu3.getName());
        map.put(stu4.getId(),stu4.getName());

        //排序
        map.forEach(new BiConsumer<Integer, String>() {
            @Override
            public void accept(Integer integer, String s) {
                System.out.println(integer+s);
            }
        });

        List list=new ArrayList();
        list.add(stu1);
        list.add(stu1);
        list.add(stu1);
        list.add(stu1);
    }
}
